﻿Public Class ButtonA

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Public Sub New(ByVal name As String)
        InitializeComponent()
        Me.Text = name
    End Sub

    Public Overrides Property BackColor As System.Drawing.Color
        Get
            Return MyBase.BackColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            If m_active = False And value <> BackgroundColorHover Then
                MyBase.BackColor = Color.FromArgb(34, 34, 34)
            Else
                MyBase.BackColor = value
            End If
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        'Add your custom paint code here
        e.Graphics.DrawString(Text, Me.Font, New SolidBrush(Me.ForeColor), (Width - Text.Length * Font.Height / 2) / 2, (Height - Me.Font.Height) / 2)
    End Sub

    Private b_hover As Color = Color.FromArgb(51, 51, 51)
    Public Property BackgroundColorHover As Color
        Get
            Return b_hover
        End Get
        Set(ByVal value As Color)
            b_hover = value
        End Set
    End Property
    Private m_hover As Color = Color.White
    Public Property ForeColorHover As Color
        Get
            Return m_hover
        End Get
        Set(ByVal value As Color)
            bg = Me.BackColor
            fc = Me.ForeColor
            m_hover = value
            f = Me.Font
        End Set
    End Property

    Private f As Font
    Private bg, fc As Color

    Private Sub ButtonA_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseHover
        Me.BackColor = BackgroundColorHover
        Me.ForeColor = ForeColorHover
        Me.Font = New Font(Font.FontFamily, Font.Size, FontStyle.Bold)
        Cursor = Cursors.Hand
        If ButtonActive = True Then ButtonActive = True
    End Sub

    Private Sub ButtonA_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave
        If m_active = True Then Exit Sub
        BackColor = bg
        ForeColor = fc
        Cursor = Cursors.Default
        Me.Font = f
    End Sub

    Public Overrides Property Text As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            MyBase.Text = value
            Me.Refresh()
        End Set
    End Property

    Private m_active As Boolean = False
    Public Property ButtonActive As Boolean
        Get
            Return m_active
        End Get
        Set(ByVal value As Boolean)
            m_active = value
            If m_active = True Then
                Me.BackColor = Color.FromArgb(241, 81, 78)
                Me.ForeColor = ForeColorHover
            Else
                Me.BackColor = bg
                Me.ForeColor = fc
            End If
            Me.Refresh()
        End Set
    End Property

End Class
